package com.huatai.xxljob.dubbo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huatai.xxljob.dto.XxlJobDTO;
import com.huatai.xxljob.entity.XxlJobGroupEntity;
import com.huatai.xxljob.entity.XxlJobInfoEntity;
import com.huatai.xxljob.entity.XxlJobLogglueEntity;
import com.huatai.xxljob.service.XxlJobGroupService;
import com.huatai.xxljob.service.XxlJobInfoService;
import com.huatai.xxljob.service.XxlJobLogglueService;
import com.huatai.xxljob.vo.XxlJobDictVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author gusiyi
 * @version 1.0
 * @className XxlJobManagerDubboApiServiceImpl
 * @description 描述：
 * @date 2024/7/3 10:56
 */
@DubboService
public class XxlJobManagerDubboApiServiceImpl implements XxlJobManagerDubboApi {

	@Autowired
	private XxlJobInfoService xxlJobInfoService;

	@Autowired
	private XxlJobGroupService xxlJobGroupService;

	@Autowired
	private XxlJobLogglueService xxlJobLogglueService;


	@Override
	public List<XxlJobGroupEntity> jobGroupList() {
		return xxlJobGroupService.list();
	}

	/**
	 * 分页查询定时任务
	 * @param xxlJobDto 查询条件
	 * @return
	 */
	@Override
	public IPage<XxlJobInfoEntity> xxlJobInfoPage(XxlJobDTO xxlJobDto) {
		return xxlJobInfoService.xxlJobInfoPage(xxlJobDto);
	}

	/**
	 * 新增/修改定时任务
	 * @param xxlJobInfoEntity
	 * @return
	 */
	@Override
	public Boolean saveOrUpdateXxlJob(XxlJobInfoEntity xxlJobInfoEntity) {
		return xxlJobInfoService.saveOrUpdateXxlJob(xxlJobInfoEntity);
	}

	/**
	 * 获取调度类型列表
	 * @return
	 */
	@Override
	public List<XxlJobDictVo> scheduleTypeList() {
		return xxlJobInfoService.scheduleTypeList();
	}

	/**
	 * 返回运行模式列表
	 * @return
	 */
	@Override
	public List<XxlJobDictVo> glueType() {
		return xxlJobInfoService.glueType();
	}

	/**
	 * 获取路由策略列表
	 * @return
	 */
	@Override
	public List<XxlJobDictVo> executorRouteStrategy() {
		return xxlJobInfoService.executorRouteStrategy();
	}

	/**
	 * 调度过期策略列表
	 * @return
	 */
	@Override
	public List<XxlJobDictVo> misfireStrategyList() {
		return xxlJobInfoService.misfireStrategyList();
	}

	/**
	 * 阻塞处理策略
	 * @return
	 */
	@Override
	public List<XxlJobDictVo> executorBlockStrategy() {
		return xxlJobInfoService.executorBlockStrategy();
	}

	/**
	 * 启动定时任务
	 * @param id
	 * @return
	 */
	@Override
	public Boolean start(Integer id) {
		return xxlJobInfoService.start(id);
	}

	/**
	 * 停止定时任务
	 * @param id
	 * @return
	 */
	@Override
	public Boolean stop(Integer id) {
		return xxlJobInfoService.stop(id);
	}

	/**
	 * 触发定时任务
	 * @param xxlJobDTO
	 * @return
	 */
	@Override
	public Boolean trigger(XxlJobDTO xxlJobDTO) {
		return xxlJobInfoService.trigger(xxlJobDTO);
	}

	/**
	 * 保存脚本
	 * @param xxlJobDTO
	 * @return
	 */
	@Override
	public Boolean glueIdeSave(XxlJobDTO xxlJobDTO) {
		return xxlJobInfoService.glueIdeSave(xxlJobDTO);
	}

	/**
	 * 获取脚本列表
	 * @param jobId
	 * @return
	 */
	@Override
	public List<XxlJobLogglueEntity> getGlueSourceList(Integer jobId) {
		return xxlJobInfoService.getGlueSourceList(jobId);
	}

	/**
	 * 删除定时任务
	 * @param id
	 * @return
	 */
	@Override
	public Boolean removeJob(Integer id) {
		return xxlJobInfoService.removeJob(id);
	}

	/**
	 * 获取脚本代码
	 * @param id
	 * @return
	 */
	@Override
	public XxlJobLogglueEntity getGlueSource(Integer id) {
		return xxlJobLogglueService.getById(id);
	}
}
